/* Copyright  2009
   @Author
   Richard Changde Yin            e-mail yinchangde@hotmail.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 *  @filename  libclient_priv.h
 */

#ifndef __LIBCLIENT_PRIV_H__
#define __LIBCLIENT_PRIV_H__

#include "esql.h"
#include <include/korr.h>

#include <sys/socket.h>

#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_SECURE_CONNECTION)

#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
#define __builtin_expect(x, expected_value) (x)
#endif

#define likely(x)	__builtin_expect((x),1)
#define unlikely(x)	__builtin_expect((x),0)

#ifndef __cplusplus
#define max(a, b)       ((a) > (b) ? (a) : (b))
#define min(a, b)       ((a) < (b) ? (a) : (b))
#endif

const char * client_sqlstate_get_unknown(void);
const char * client_sqlstate_get_not_error(void);
const char * client_sqlstate_get_cant_connect(void);

void client_set_default_port(unsigned int port);
void client_set_error(ESQL *esql, int errcode, const char *sqlstate);
void client_set_extended_error(ESQL *esql, int errcode,
                                const char *sqlstate,
                                const char *format, ...);
void client_free_old_query(ESQL *esql);

int  client_connect_with_timeout(int fd, const struct sockaddr *name,
                         unsigned int namelen, int32_t timeout);

void client_close_free_options(ESQL *esql);
void client_close_free(ESQL *esql);

/* Hook Methods */
bool client_cli_read_query_result(ESQL *esql);
ESQL_RES *client_cli_use_result(ESQL *esql);
void client_cli_fetch_lengths(uint32_t *to, ESQL_ROW column,
                       uint32_t field_count);
void client_cli_flush_use_result(ESQL *drizzle);

#endif
